using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using CMS.BIZ;
using System.Web;

namespace CMS.Web.UI.UserControls
{
    public class Download : UserControl
    {

        private BizDownloadFolder folder;

        protected Repeater repeaterDownloadFolder;
        protected Repeater repeaterDownload;

        public Download()
        {
            base.Init += new EventHandler(Download_Init);
        }

        protected string ParentFolderQueryString
        {
            get { return folder == null || folder.ParentFolderID == null ? "" : folder.ParentFolderID.ToString(); }
        }

        void Download_Init(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SetCurrentFolderFromQueryString();
                BindFolder();
                BindFile();
            }
        }

        private void SetCurrentFolderFromQueryString()
        {
            string str = Request.QueryString["CurrentFolder"];
            if (!string.IsNullOrEmpty(str)) folder = Page.BizDownloadFolderProvider.Find(int.Parse(str));
        }

        private void BindFolder()
        {
            int? folderId = null;
            string str = Request.QueryString["CurrentFolder"];
            if (!string.IsNullOrEmpty(str)) folderId = int.Parse(str);
            repeaterDownloadFolder.DataSource = Page.BizDownloadFolderProvider.ReadByFolder(folderId);
            repeaterDownloadFolder.DataBind();
        }

        private void BindFile()
        {
            int? folderId = null;
            string str = Request.QueryString["CurrentFolder"];
            if (!string.IsNullOrEmpty(str)) folderId = int.Parse(str);
            repeaterDownload.DataSource = Page.BizDownloadProvider.ReadByFolder(folderId);
            repeaterDownload.DataBind();
        }

    }
}
